import { orderBy } from "lodash";
import { getVisitTimesDataAllApi } from '../apis/logApi.js';

// 排序后的数据
export default async function useOrderByData(source,key = (e) => e.logData.num,order = 'desc') {
    const { code, rows } = await getVisitTimesDataAllApi();
    if (code === 200) {
        const list = source.map((item)=>{
            item.logData = rows.find(it=>it.id === item.id) || {num:''};
            return item;
        });
        if (typeof key === 'string') {
            return orderBy(list, key, order);
        } else {
            return orderBy(list, key, order);
        }
    }
   
}